package com.gomyb.storage;

import com.gomyb.storage.model.CloudStorageAuth;
import com.gomyb.storage.model.SingleData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.InputStream;

/**
 * @author <a href="mailto:hellohesir@gmail.com">Mr_He</a>
 * 2019/3/6 19:45
 */
@Component
public class StorageHandler {

    @Autowired(required = false)
    public AbstractCloudServiceImpl abstractCloudServiceImpl;

    @PostConstruct
    public void init() {
        if (null != abstractCloudServiceImpl) {
            CloudStorageAuth cloudStorageAuth = abstractCloudServiceImpl.init();
            if (null != cloudStorageAuth) {
                SingleData.getSingleData().setCloudStorageAuth(cloudStorageAuth);
            }
        } else {
            throw new RuntimeException("云存储初始化失败。。。。。。。。");
        }
    }

    public boolean upload(InputStream inputStream) {
        return abstractCloudServiceImpl.upload(inputStream);
    }

}
